from app.models.log_models import LoginHistory

async def record_login_history(user_id: int, username: str, ip_address: str, 
                              user_agent: str, login_status: bool, login_message: str = None):
    """记录登录历史"""
    try:
        await LoginHistory.create(
            user_id=user_id,
            username=username,
            ip_address=ip_address,
            user_agent=user_agent,
            login_status=login_status,
            login_message=login_message
        )
        return True
    except Exception as e:
        print(f"记录登录历史失败: {str(e)}")
        return False